# -*- encoding:utf-8 -*-
"""
@作者：jiajun_Tang
@文件名：register_activity.py
@时间：2023/4/26  下午 02:24
@文档说明: 登录界面事件触发
"""

from PyQt5.QtWidgets import QDialog, QMessageBox
from graphical_user_interface.register_gui import Ui_registerWindow


class startup_window(QDialog):
    def __init__(self, *args, **kwargs):
        # QtWidgets.QMainWindow.__init__(self)
        super().__init__(*args, **kwargs)
        self.ui = Ui_registerWindow()
        self.ui.setupUi(self)
        self.ui.login_button.clicked.connect(self.login_button_event)
        self.ui.clear_button.clicked.connect(self.clear_button_event)

    def keyPressEvent(self, event):
        # 这里event.key（）显示的是按键的编码
        self.login_button_event()
        # print("按下：" + str(event.key()))

    def login_button_event(self):
        self.account_value = self.ui.edit_account.text().strip()  # 登录账户
        self.password_value = self.ui.edit_password.text().strip()  # 登录密码

        if self.account_value is None or self.password_value is None:
            # 后两项分别为按钮(以|隔开，共有7种按钮类型，见示例后)、默认按钮(省略则默认为第一个按钮)
            reply = QMessageBox.information(self, "提示", "请输入完整账号或密码！",
                                            QMessageBox.Yes | QMessageBox.No, QMessageBox.Yes)

        elif self.account_value == 'hsk' and self.password_value == '123':
            self.accept()
        else:
            # 后两项分别为按钮(以|隔开，共有7种按钮类型，见示例后)、默认按钮(省略则默认为第一个按钮)
            reply = QMessageBox.information(self, "提示", "请输入正确账号或密码！",
                                            QMessageBox.Yes | QMessageBox.No, QMessageBox.Yes)

    def clear_button_event(self):
        self.ui.edit_account.setText('')
        self.ui.edit_password.setText('')  # 登录密码
        # self.ui.edit_account.selectAll()  # 选择全部内容
        self.ui.edit_account.setFocus()  # 获得焦点
